import 'dart:io';

import 'package:flutter/material.dart';

class AssetsImageListPage extends StatefulWidget {
  const AssetsImageListPage(
      {super.key,
      required this.assetsBarcodePath,
      required this.assetsQrcodePath,
      required this.onSelectCallBack});

  final String assetsBarcodePath;
  final String assetsQrcodePath;
  final Function(String value) onSelectCallBack;

  @override
  State<AssetsImageListPage> createState() => _AssetsImageListPageState();
}

class _AssetsImageListPageState extends State<AssetsImageListPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('barcode'),
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Row(
                children: [
                  GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: () {
                      widget.onSelectCallBack(widget.assetsBarcodePath);
                      Navigator.pop(context);
                    },
                    child: Image.file(
                      File(widget.assetsBarcodePath),
                      width: (MediaQuery.sizeOf(context).width - 32) / 4,
                      height: (MediaQuery.sizeOf(context).width - 32) / 4,
                      fit: BoxFit.fill,
                    ),
                  ),
                  GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: () {
                      widget.onSelectCallBack(widget.assetsQrcodePath);
                      Navigator.pop(context);
                    },
                    child: Image.file(
                      File(widget.assetsQrcodePath),
                      width: (MediaQuery.sizeOf(context).width - 32) / 4,
                      height: (MediaQuery.sizeOf(context).width - 32) / 4,
                      fit: BoxFit.fill,
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
